vue3 中的axios的使用,使用Vue.prototype 报错问题

您所在的位置:网站首页 prototypejs 173下载 vue3 中的axios的使用,使用Vue.prototype 报错问题

vue3 中的axios的使用,使用Vue.prototype 报错问题

2023-10-30 08:52| 来源: 网络整理| 查看: 265

vue2中axois的使用 import Vue from 'vue'; import axios from 'axios'; Vue.prototype.$ajax = axios;

或者,使用Vue.use(httpRequest, config)实现引入

// main.js import httpRequest from 'httpRequest.js'; Vue.use(httpRequest, config); // httpRequest.js // 提供给Vue httpRequest.install = function (Vue, options = {}) { ... Vue.prototype.$ajax = httpRequest; } export default httpRequest;

 

vue3

注意: 因vue3中不在使用 Vue.use,而是createApp(App),此时使用use()拿到的第一个参数不在是以前的Vue

Vue3中的使用

import Vue from 'vue'; import axios from 'axios'; Vue.config.globalProperties.$ajax = axios ;

或者,使用createApp(App).use(httpRequest, config)实现引入

// main.js import httpRequest from 'httpRequest.js'; createApp(App).use(httpRequest, config); // httpRequest.js // 提供给Vue httpRequest.install = function (app, options = {}) { ... app.config.globalProperties.$ajax = httpRequest; } export default httpRequest;


【本文地址】


今日新闻


推荐新闻


CopyRight 2018-2019 办公设备维修网 版权所有 豫ICP备15022753号-3